package main

import (
	"context"
	"fmt"
)

type UserInfo struct {
	name string
}

func main() {
	a := context.Background()
	b := context.WithValue(a, "k1", "v1")
	c := context.WithValue(b, "k2", "v2")
	d := context.WithValue(c, "k1", "vo1")

	fmt.Printf("k1 of b: %s\n", b.Value("k1"))
	fmt.Printf("k1 of c: %s\n", d.Value("k1"))
	fmt.Printf("k2 of d: %s\n", d.Value("k2"))

	user := UserInfo{"小李"}
	uc := context.Background()
	uc = context.WithValue(uc, "name", user)
	getUser(uc)

}

func getUser(ctx context.Context) {
	fmt.Println(ctx.Value("name").(UserInfo).name)
}
